//index.js
//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTabsIndex: 2,
    index: 1,
    num: 1,
    inputText: "",
    unFinishList: [],
    finishList: [],
    afterSale: [],
    time: '',
    orderId: null,
    unFinishLeg: 0,
    finishLeg: 0,
    afterSaleLeg: 0,
    current: 0,
    height: wx.getSystemInfoSync().windowHeight
  },

  /**
   * 获取未完成订单列表
   */
  getUnfinishOrderList: function () {
    let that = this;
    wx.showLoading({
      title: '正在加载',
    })
    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/receiveFindUnFinish/v2',
      method: 'post',
      data: {
        userId: wx.getStorageSync("userId"),
      },
      success: function (res) {
        console.log("zl")
        console.log(res)
        wx.hideLoading()
        if (res.data.code === 200) {
          console.log("weiwanc")
          console.log(res.data)
          that.setData({
            unFinishList: res.data.data,
            unFinishLeg: res.data.data.length
          })
          console.log(that.data.unFinishList)
          console.log(that.data.unFinishLeg + 'cangdu')
          // wx.hideLoading()
        }
      },fail(){
        wx.hideLoading()
      }
    })
  },

  /**
   * 获取已完成订单列表
   */
  getFinishOrderList: function () {
    let that = this;
    wx.showLoading({
      title: '正在加载',
    })
    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/receiveFindFinish',
      method: 'post',
      data: {
        userId: wx.getStorageSync("userId"),

      },
      success: function (res) {
        console.log("yiwanc")
        console.log(res)
        wx.hideLoading();
        if (res.data.code === 200) {
          that.setData({
            finishList: res.data.data,
            finishLeg: res.data.data.length
          })
         
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if (options.class == 0) {
      this.getUnfinishOrderList();
      this.setData({
        currentTabsIndex: 0,
        current: 0
      })
    } else if (options.class == 1) {
      this.getFinishOrderList();
      this.setData({
        currentTabsIndex: 1,
        current: 1
      })
    } else {
      // this.getAfterSale();
      console.log(111);
      this.setData({
        currentTabsIndex: 2,
        current:2
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.animation = wx.createAnimation()

  },

  /**
   * 空白页面去抢单事件函数
   */
  goGrabOrder: function () {
    wx.redirectTo({
      url: '../demand/demand',
    })
  },

  // 详情页
  detail: function (e) {
    let that = this;
    that.setData({
      orderId: e.currentTarget.dataset.id
    })
    // console.log(e.currentTarget.dataset.orderid)
    wx.navigateTo({
      url: '../grabSuccess/grabSuccess?orderId=' + this.data.orderId,
    })
  },

  inputText: function (e) {
    let that = this;
    // console.log(e);
    that.setData({
      inputText: e.target.dataset.name
    })

  },

  text: function (e) {
    let that = this;
    // console.log(e);
    that.setData({
      text: e.target.dataset.text
    })
  },
  itemTap: function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(index);
    var that = this;
    this.setData({
      currentTabsIndex: index
    })
    if (index == 0) {
      that.getUnfinishOrderList()
      that.setData({
        current: 0
      })
    } else if (index == 1) {
      that.getFinishOrderList()
      that.setData({
        current: 1
      })
    } else {
      that.setData({
        current: 2
      })
      // that.getAfterSale()
    }
  },
  swiper(e) {
    console.log(e);
    var that = this;
    var current = e.detail.current;
    this.setData({
      current: current,
      currentTabsIndex: current
    })
    if (current == 0) {
      that.getUnfinishOrderList()
    } else if (current == 1) {
      that.getFinishOrderList()
    } else {
      // that.getAfterSale()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})